
<template>
  <div class="layoutlist">
    <el-button type="primary" size="default" @click="creationLayout"
      >新建企划</el-button
    >
    <el-table :data="tableData" border stripe style="margin-top: 10px">
      <el-table-column
        v-for="col in columns"
        :prop="col.id"
        :key="col.id"
        :label="col.label"
        align="center"
      >
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="{ row }">
          <div>
            <el-button type="text" size="default" @click="onEdit(row)"
            :disabled="!qxobj.save"
              >编辑</el-button
            >
            <el-button
              type="text"
              size="default"
              style="color: red"
              @click="onDelete(row.id)"
              :disabled="!qxobj.del"
              >删除</el-button
            >
          </div>
          <!-- <div>
            <el-button type="text" size="default">套装列表</el-button>
            <el-button type="text" size="default">企划进度</el-button>
          </div> -->
        </template>
      </el-table-column>
    </el-table>
    <!-- <pagination/> -->
    <new-layout :layoutVisible="dialogFormVisible" :form="layoutForm" @onFiltForm="onFiltForm" @ondialogFormVisible="ondialogFormVisible" @postApigetplanning="postApigetplanning" />
  </div>
</template>

<script>
import {
  postApigetplanning,
  postApidelplanning,
} from "@/api";
import layout from "@/mixins/layout.js"
import table from "@/mixins/table.js"
export default {
  mixins:[ layout, table ],
  data() {
    return {
      qxobj:{},
      dialogFormVisible: false,
      rules: {
        date: [{ required: true, message: "请选择企划名称", trigger: "blur" }],
        ddltime: [
          { required: true, message: "请选择最终完成日期", trigger: "blur" },
        ],
      },
      tableData: [],
      columns: [
        {
          label: "企划名称",
          id: "date",
        },
        {
          label: "最终完成日期",
          id: "ddltime",
        },
        {
          label: "创建时间",
          id: "createtime",
        },
      ],
    };
  },
  activated() {
    this.qxobj = JSON.parse(this.$route.query.qxobj)
    this.postApigetplanning();
  },
  methods: {
    // 企划列表
    postApigetplanning() {
      postApigetplanning().then((res) => {
        console.log("企划列表", res);
        this.tableData = res.data;
      });
    },
    // 删除
    onDelete(id) {
      this.$confirm("此操作将永久删除该企划, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          postApidelplanning(id)
            .then((res) => {
              this.$message.success("删除成功");
              this.postApigetplanning();
            })
            .catch((err) => {
              this.$message.warning(err.msg);
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    // 编辑
    onEdit(e) {
      this.layoutForm = {
        date: e.date,
        ddltime: e.ddltime,
        id: e.id,
      };
      this.dialogFormVisible = true;
    },
    
  },
};
</script>

<style lang="scss" scoped>
.layoutlist {
  @include global-back;
}
</style>